//
//  myMovieViewController.m
//  豆瓣2
//
//  Created by dllo on 15/12/19.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "myMovieViewController.h"
#import "DataBaseSingleton.h"
#import "Movie.h"
#import "MovieDataViewController.h"
@interface myMovieViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic ,retain)NSMutableArray *allArray;
@property (nonatomic ,retain)UITableView *mytable;

@end

@implementation myMovieViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.mytable = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.mytable.backgroundColor = [UIColor whiteColor];
    
    self.mytable.delegate = self;
    self.mytable.dataSource =self;
    
    [self.mytable registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:self.mytable];
    
    self.allArray = [NSMutableArray array];
NSMutableArray *array = [[DataBaseSingleton shareDataBase]selectUser];
    
    for (Movie *movie in array) {
        
        [self.allArray addObject:movie.movieName];
    }
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.allArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    cell.textLabel.text = [self.allArray objectAtIndex:indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MovieDataViewController *movieDate = [[MovieDataViewController alloc]init];
    movieDate.movie = [[[DataBaseSingleton shareDataBase]selectUser]objectAtIndex:indexPath.row];
    
    [self.navigationController pushViewController:movieDate animated:YES];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
